class BudgetExceptionsController < ApplicationController
  # GET /budget_exceptions
  # GET /budget_exceptions.json
  def index
    if (!params[:account_id].nil?) then
      budget_exception = BudgetException.new
      budget_exception.account_id= params[:account_id]
      budget_exception.amount = params[:amount]
      budget_exception.category_id = params[:category_id]

      budget_exception.save!

    end
    @budget_exceptions = BudgetException.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @budget_exceptions }
    end
  end

  # GET /budget_exceptions/1
  # GET /budget_exceptions/1.json
  def show
    @budget_exception = BudgetException.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @budget_exception }
    end
  end

  # GET /budget_exceptions/new
  # GET /budget_exceptions/new.json
  def new
    @budget_exception = BudgetException.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @budget_exception }
    end
  end

  # GET /budget_exceptions/1/edit
  def edit
    @budget_exception = BudgetException.find(params[:id])
  end

  # POST /budget_exceptions
  # POST /budget_exceptions.json
  def create
    @budget_exception = BudgetException.new(params[:budget_exception])

    respond_to do |format|
      if @budget_exception.save
        format.html { redirect_to @budget_exception, notice: 'Budget exception was successfully created.' }
        format.json { render json: @budget_exception, status: :created, location: @budget_exception }
      else
        format.html { render action: "new" }
        format.json { render json: @budget_exception.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /budget_exceptions/1
  # PUT /budget_exceptions/1.json
  def update
    @budget_exception = BudgetException.find(params[:id])

    respond_to do |format|
      if @budget_exception.update_attributes(params[:budget_exception])
        format.html { redirect_to @budget_exception, notice: 'Budget exception was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @budget_exception.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /budget_exceptions/1
  # DELETE /budget_exceptions/1.json
  def destroy
    @budget_exception = BudgetException.find(params[:id])
    @budget_exception.destroy

    respond_to do |format|
      format.html { redirect_to budget_exceptions_url }
      format.json { head :ok }
    end
  end
end
